package com.zxlspace.proxy;

/**
 * 使用静态代理实现Runnable接口
 */
public class Web12306 implements Runnable{
    private int num = 500;

    @Override
    public synchronized void run() {
        while (true) {
            if (num <= 0) {
                break;
            }
            System.out.println(Thread.currentThread().getName() + "抢到了" + num--);
        }
    }

    public static void main(String[] args) {
        //真实角色
        Web12306 web12306 = new Web12306();
        //代理角色：持有真实角色的引用
        Thread t1 = new Thread(web12306, "黄牛1");
        Thread t2 = new Thread(web12306, "黄牛2");
        Thread t3 = new Thread(web12306, "黄牛3");
        //二者实现了相同的接口
        t1.start();
        t2.start();
        t3.start();
    }
}
